﻿CREATE PROCEDURE [dbo].[Subscriber_Create]
	@email nvarchar(256)
AS
BEGIN
	SET @email = LOWER(@email)
	IF EXISTS (SELECT * FROM [dbo].[email_Subscriber] WHERE [Email] = @email)
	BEGIN
		RAISERROR ('EmailExists',9,1)
		RETURN
	END
	ELSE
	BEGIN
		DECLARE @code NVARCHAR(16) = [dbo].[RandString](16)

		INSERT INTO [dbo].[email_Subscriber] ([Email], [ActivationCode])
		VALUES (@email, @code)

		SELECT @email AS 'Email', @code AS 'ActivationCode'
	END
END